<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 11/13/18
 * Time: 3:57 PM
 */
session_start();
define('DIR_ROOT', dirname(__FILE__).'/');
require_once __DIR__ . '/autoload.php';

date_default_timezone_set("Asia/Shanghai");

// 处理路由 index.php?r=ss/sd
$route_start = strpos($_SERVER['SCRIPT_NAME'], 'index.php');
$route_end = strpos($_SERVER['REQUEST_URI'], '?');
$route_end = $route_end === false ? strlen($_SERVER['REQUEST_URI']) : $route_end;
$route = substr($_SERVER['REQUEST_URI'], $route_start, $route_end - $route_start);
if (empty($route)) {
    exit('Access denied!');
}

// 解析路由
$routers = explode('/', $route);
if (count($routers) !== 2) {
    exit('Access denied!!');
}

if (\caroltc\jenkinsapp\library\Facade::isDebugMode()) {
    \caroltc\jenkinsapp\library\Facade::setDebugKey();
}

$class = ucfirst($routers[0]);
$method = $routers[1];
$class_name = '\caroltc\jenkinsapp\controller\\'.$class;
if (!class_exists($class_name )) {
    exit('Access denied!!!');
}
$controller = new $class_name;
if (!method_exists($controller, $method)) {
    exit('Access denied!!!!');
}

$controller->$method(); // run method